package com.spring.datasource.util;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * 动态数据源持有者，负责利用ThreadLocal存取数据源名称
 */
public class DynamicDataSourceHolder {
    /**
     * 本地线程共享对象
     */
    private static final ThreadLocal<String> THREAD_LOCAL = new ThreadLocal();

    private static final ThreadLocal<String> LOG_LOCAL = new InheritableThreadLocal();

//    private static final TransmittableThreadLocal<String> LOG_LOCAL = new TransmittableThreadLocal();

    public static void putDataSource(String name) {
        THREAD_LOCAL.set(name);
    }

    public static String getDataSource() {
        return THREAD_LOCAL.get();
    }

    public static void removeDataSource() {
        THREAD_LOCAL.remove();
    }

    public static void putThreadLocal(String name) {
        LOG_LOCAL.set(name);
    }

    public static String getThreadLocal() {
        return LOG_LOCAL.get();
    }

    public static void removeThreadLocal() {
        LOG_LOCAL.remove();
    }
}
